<?php

//$username = "akinlax";
//$password = "Flourish75";
$ch = curl_init();

function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
{
    global $ch;
    curl_setopt($ch, CURLOPT_HEADER, $header);
    //curl_setopt($ch, CURLOPT_NOBODY, $header);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
//    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    if ($p) {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
    }
    $result = curl_exec($ch);
    if ($result) {
        return $result;
    } else {
        return curl_error($ch);
    }
}


$sPageAndHeader = cURL('https://svpr-isg-a1.isaca.org/ISGweb/LogIn/Login.aspx', TRUE);

//*****************************************
//get html
include('../hlib/simple_html_dom.php');
$html = str_get_html($sPageAndHeader);
$aInputClean = array();
$a = $html->find('input');

foreach($html->find('input') as $oElement) {
    if(isset($oElement->name)) {
        $aInputClean[$oElement->name] = $oElement->value;
    }
}

$aInputClean['txttxtUsername'] = 'akinlax';
$aInputClean['txttxtPassword'] = 'Flourish75';
$aInputClean['__EVENTTARGET'] = 'btnGo';
unset($aInputClean['btnGo']);

//*******************************************
//get cookie
preg_match_all('%Set-Cookie: ([^;]+);%',$sPageAndHeader, $aCookies);

$sCookies = '';
for($i=0;$i<count($aCookies[0]);$i++)
    $sCookies .= $aCookies[1][$i].";";

$sPost = '';
foreach($aInputClean as $key => $item) {
    $sPost .= $key . '=' . $item . '&';
}


echo cURL('https://svpr-isg-a1.isaca.org/ISGweb/LogIn/Login.aspx', NULL, NULL, $sPost);
//echo '<pre>';print_r($sHeader);echo '</pre>';die();